package de.ghost23.common.statemachine {
	import flash.events.Event;

	/**
	 * This event is used by the StateMachine.
	 * <p>There are two types of events supported:
	 * <ul>
	 * <li>NEW_STATE: fired, when a new state is entered</li>
	 * <li>AIMED_STATE_REACHED: fired, when the state, that was set via <code>stateMachine.aimForState(state:State)</code>
	 * has been reached.</li>
	 * </ul>
	 * The event holds information about the previous, the current and the target state, if those are
	 * defined.</p>
	 * @author Sven Busse
	 * @version 1.0
	 */
	public class StateMachineEvent extends Event {

		/**
		 * ID for the event, that a new state has been entered
		 */
		public static const NEW_STATE:String = "onNewState";

		/**
		 * ID for the event, that a state, that was set via <code>stateMachine.aimForState(state:State)</code>
		 * has been reached.
		 */
		public static const AIMED_STATE_REACHED:String = "onAimedStateReached";

		/**
		 * The state, that was exited before entering the new state, or null, if
		 * the current state is the first state after initialization of the state machine.
		 */
		public var previousState:State;

		/**
		 * The currently active state.
		 */
		public var currentState:State;

		/**
		 * A state, that was set via <code>stateMachine.aimForState(state:State)</code>
		 * has been reached, or null, if none was set.
		 */
		public var targetState:State;

		/**
		 * Constructs a new event.
		 * @param type The type of this event. See the static constants for possible types.
		 * @param previousState The state, that was exited before entering the new state, or null, if
		 * the current state is the first state after initialization of the state machine.
		 * @param currentState The currently active state.
		 * @param targetState A state, that was set via <code>stateMachine.aimForState(state:State)</code>
		 * has been reached, or null, if none was set.
		 */
		public function StateMachineEvent(type:String, previousState:State, currentState:State, targetState:State) {
			super(type, false, false);

			this.previousState = previousState;
			this.currentState = currentState;
			this.targetState = targetState;
		}

		override public function clone():Event {
			return new StateMachineEvent(type, previousState, currentState, targetState);
		}

		override public function toString():String {
			return "com.ghost23.common.statemachine.StateMachineEvent";
		}
	}
}